using BasicScript.Component;
using Game.Main.Model;
using SimpleJSON;
using UnityEngine;

namespace Game.Component
{
	public class PhotoItem : BaseItem
	{
		private int photoId;

		public override void Init(ItemArchiveData data)
		{
			base.Init(data);
			if (data.state == 0)
			{
				photoId = Random.Range(1, 5);
			}
			else
			{
				photoId = data.state;
			}
			InitPhoto();
		}

		private void InitPhoto()
		{
			SpriteAssets component = model.GetComponent<SpriteAssets>();
			string value = "photo_" + photoId;
			if (!(component != null) || !(component.data != null) || component.data.sprites == null)
			{
				return;
			}
			for (int i = 0; i < component.data.sprites.Count; i++)
			{
				if (component.data.sprites[i] != null && component.data.sprites[i].name.Equals(value))
				{
					model.GetComponent<SpriteRenderer>().sprite = component.data.sprites[i];
				}
			}
		}

		public override void PackData(JSONObject obj)
		{
			base.PackData(obj);
			obj["33"] = photoId;
		}
	}
}
